package sfmc.biz.serviceImpl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import sfmc.biz.dao.SfmcEmpStatusDao;
import sfmc.biz.service.SfmcEmpStatusService;
import sfmc.biz.vo.Sfmc_TB_EMPSTATUS;

@Service("SfmcEmpStatusService")
public class SfmcEmpStatusServiceImpl implements SfmcEmpStatusService{
	
	protected Log log = LogFactory.getLog(this.getClass());
	
	@Resource(name="SfmcEmpStatusDao")
	private SfmcEmpStatusDao sfmcEmpStatusDao;
	
	public void setSfmcEmpStatusDao(SfmcEmpStatusDao sfmcEmpStatusDao) {
		this.sfmcEmpStatusDao = sfmcEmpStatusDao;
	}

	@Override
	public List<Sfmc_TB_EMPSTATUS> getEmpStatusList(Sfmc_TB_EMPSTATUS sfmc_TB_EMPSTATUS) {
		return getEmpStatusList(sfmc_TB_EMPSTATUS, false);
	}
	public List<Sfmc_TB_EMPSTATUS> getEmpStatusList(Sfmc_TB_EMPSTATUS sfmc_TB_EMPSTATUS, boolean isExcel) {
		
		String where = "";
		
		try{
			if(!"".equals(sfmc_TB_EMPSTATUS.getSearchEmpName())){
				where += "AND C.EmpName LIKE '%"+sfmc_TB_EMPSTATUS.getSearchEmpName()+"%'\n";
			}

			if(isExcel){
				where += "ORDER BY A.ORDDATE, A.ORDDATE \n";
			}else{
				where += "ORDER BY A.ORDDATE, A.ORDDATE LIMIT "+sfmc_TB_EMPSTATUS.getOffSet()+", "+sfmc_TB_EMPSTATUS.getPageSize()+" \n";
			}
			
			sfmc_TB_EMPSTATUS.setWhere(where);
			
			return sfmcEmpStatusDao.getEmpStatusList(sfmc_TB_EMPSTATUS);
			
		}catch(Exception e){
			log.error(e);
			return null;
		}
	}

	@Override
	public int getRecordCount(Sfmc_TB_EMPSTATUS sfmc_TB_EMPSTATUS) {
		
		String where = "";
		
		try{
			if(!"".equals(sfmc_TB_EMPSTATUS.getSearchEmpName())){
				where += "AND C.EmpName LIKE '%"+sfmc_TB_EMPSTATUS.getSearchEmpName()+"%'\n";
			}

			sfmc_TB_EMPSTATUS.setWhere(where);
			return sfmcEmpStatusDao.getRecordCodunt(sfmc_TB_EMPSTATUS);
			
		}catch(Exception e){
			log.error(e);
			return 0;
		}
		
	}
}
